package heven.holt.library.binding

import android.view.View
import android.widget.ProgressBar
import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.paging.LoadState

@BindingAdapter("android:bindState")
fun bindState(textView: TextView, loadState: LoadState) {
    val hintText = when (loadState) {
        is LoadState.Error -> {
            "重试"
        }
        is LoadState.Loading -> {
            "加载中..."
        }
        else -> {//END
            "没有更多数据了~"
        }
    }
    textView.text = hintText
}

@BindingAdapter("android:bindState")
fun bindState(progressBar: ProgressBar, loadState: LoadState) {
    progressBar.visibility = if (loadState is LoadState.NotLoading) View.GONE else View.VISIBLE
}